<%@ page import="com.qimei.onerice.service.impl.OrderServiceImpl" %>
<%@ page import="com.qimei.onerice.entity.Order" %>
<%@ page import="com.qimei.onerice.service.impl.OrderDetailServiceImpl" %>
<%@ page import="com.qimei.onerice.entity.OrderDetail" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.List" %>
<%@ page import="com.qimei.onerice.service.impl.DishServiceImpl" %><%--
  Created by IntelliJ IDEA.
  User: aaa
  Date: 2023/12/18
  Time: ฅ(΅•ㅅ•΅❀)ฅ 10:26
--%>
<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false" language="java" %>
<html>
<head>
	<title>购物车</title>
	<style>
		.table tbody td {
			vertical-align: middle;
		}
	</style>
	<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
</head>
<body>
<jsp:include page="/view/common/header.jsp"></jsp:include>

<div class="container my-3">
	<%
		// 获取当前的订单（购物车）
		Order currentOrder = new OrderServiceImpl().getCurrentOrder();
		if (currentOrder != null) {
			pageContext.setAttribute("orderId", currentOrder.getOrderId());
	%>
	<div class="d-flex py-3"><h3>总金额:<%= currentOrder.getTotalAmount() %> ￥ </h3> <a class="mx-3 btn btn-primary" href="<c:url value="/order?action=checkout&orderId=${orderId}"/>"><i class="fas fa-cash-register">结账</i></a></div>
	<table class="table table-light">
		<thead>
		<tr>
			<th scope="col">商品名称</th>
			<th scope="col">类别</th>
			<th scope="col">单价</th>
			<th scope="col">数量</th>
			<th scope="col">小计</th>
			<th scope="col">取消</th>
		</tr>
		</thead>
		<tbody>
        <%
	        List<OrderDetail> orderDetailList = new OrderDetailServiceImpl().getOrderDetailListByOrderId(currentOrder.getOrderId());
			pageContext.setAttribute("orderDetailList", orderDetailList);
        %>
		<c:forEach var="detail" items="${orderDetailList}">
		<tr>
			<td>${detail.dishName}</td>
			<td>${detail.categoryName}</td>
			<td>${detail.unitPrice}</td>
			<td>
				<form action="/checkout" method="post" class="form-inline">
					<div class="form-group d-flex justify-content-between">
						<a class="btn bnt-sm btn-incre d-flex align-items-center" href="<c:url value="/quantity?action=add&orderDetailId=${detail.orderDetailId}"/>"><i class="bi bi-plus-square-fill"></i></a>
						<input type="text" name="quantity" class="form-control smaller-width" value="${detail.quantity}" readonly>
						<a class="btn btn-sm btn-decre d-flex align-items-center" href="<c:url value="/quantity?action=reduce&orderDetailId=${detail.orderDetailId}"/>"><i class="bi bi-dash-square-fill"></i></a>
					</div>
				</form>
			</td>
			<td>${detail.subtotal}</td>
			<td><a href="<c:url value="/orderDetail?action=delete&orderDetailId=${detail.orderDetailId}"/>" class="btn btn-sm btn-danger">删除</a></td>
		</tr>
		</c:forEach>
		</tbody>
	</table>
	<%}%>
</div>
<jsp:include page="/view/common/footer.jsp"></jsp:include>
</body>
</html>
